/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.saar.penguin.give3dreplay.eyetracking;

import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Circle;
import com.jme.scene.Geometry;
import com.jme.scene.Node;
import com.jme.scene.Spatial.CullHint;
import com.jme.scene.Spatial.LightCombineMode;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author koller
 */
public class FixationMarker {
    private Node parent;
    private ArrayBlockingQueue<Geometry> markers;
    private float markerRadius;

    public FixationMarker(Node parent, float markerRadius, int simultaneousMarkers) {
        this.parent = parent;
        this.markerRadius = markerRadius;
        markers = new ArrayBlockingQueue<Geometry>(simultaneousMarkers);
    }

    public void fixate(int x, int y) {
        try {

            // ensure that number of markers on screen is not exceeded
            if (markers.remainingCapacity() == 0) {
                Geometry old = markers.take();
                parent.detachChild(old);
            }

            // draw new fixation marker
            Circle c = new Circle("fixation", 10, markerRadius);
            markers.offer(c);

            c.setDefaultColor(ColorRGBA.yellow);

            c.setRenderQueueMode(Renderer.QUEUE_ORTHO);
            c.setLocalTranslation(x, y, 0);

            c.setLightCombineMode(LightCombineMode.Off);
            c.setCullHint(CullHint.Never);

            c.updateRenderState();

            parent.attachChild(c);
            parent.updateGeometricState(0.0f, true);
            parent.updateRenderState();
        } catch (InterruptedException ex) {
            Logger.getLogger(FixationMarker.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
